<?php defined('SYSPATH') or die('No direct script access.');

class Helper_User
{
	public static function get_logged()
	{
		$coocietoken = Cookie::get('token');
		if ($coocietoken == "") {
			return "";
			exit();
		}

		$sqltoken = md5($coocietoken.$_SERVER["REMOTE_ADDR"]);
			
		$user = ORM::factory('user')->where('token','=',$sqltoken)->find();


		return $user->id;


	}


	public static function logoff()
	{
		Cookie::delete('token');
	}


	

	
	//Проверка, подписан ли админ на оповещения по тикету
	public static function is_subscribed($ticket){

		
		//ищем подписку админа на тикет
		$result = ORM::factory('subscriber')
		->where('admin_id','=',Helper_User::get_logged())
		->where('ticket_id','=',$ticket)
		->find();
		
		return $result->loaded();
	}

}


